package com.pg.controller;


import java.util.Arrays;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.aspect.annotation.PermissionData;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pg.entity.LiklUser;
import com.pg.service.ILiklUserService;

/**
 * @Description: 用户表
 * @Author: jeecg-boot
 * @Date:   2020-08-12
 * @Version: V1.0
 */
@RestController
@RequestMapping("/pg/liklUser")
public class LiklUserController extends JeecgController<LiklUser, ILiklUserService> {
	@Autowired
	private ILiklUserService liklUserService;
	
	/**
	 * 分页列表查询
	 *
	 * @param liklUser
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "查询likl用户")
	@GetMapping(value = "/list")
	@PermissionData(pageComponent="modules/pg/EipProductionOrder/EipProductionOrderList")
	public Result<?> queryPageList(LiklUser liklUser,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {

//		QueryWrapper<LiklUser> queryWrapper = QueryGenerator.initQueryWrapper(liklUser, req.getParameterMap());
//		Page<LiklUser> page = new Page<LiklUser>(pageNo, pageSize);
//		IPage<LiklUser> pageList = liklUserService.page(page, queryWrapper);
//		return Result.ok(pageList);

		Result<IPage<LiklUser>> result = new Result<IPage<LiklUser>>();
		Page<LiklUser> page = new Page<LiklUser>(pageNo, pageSize);
//		System.out.println("1111111111111111111111111111111");
//		System.out.println(req.getParameterMap().toString());
//		System.out.println("1111111111111111111111111111111");
//		Map<String, String[]> parameterMap = req.getParameterMap();
//		System.out.println(JSON.toJSON(parameterMap));
//		System.out.println("2222222222222222222222222222222");
		IPage<LiklUser> pageList = liklUserService.selectForList(page, liklUser, req.getParameterMap());
		result.setSuccess(true);
		result.setResult(pageList);
		return result;
	}
	
	/**
	 *   添加
	 *
	 * @param liklUser
	 * @return
	 */
	@RequiresPermissions("user:add")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody LiklUser liklUser) {
		liklUserService.save(liklUser);
		return Result.ok("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param liklUser
	 * @return
	 */
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody LiklUser liklUser) {
		liklUserService.updateById(liklUser);
		return Result.ok("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		liklUserService.removeById(id);
		return Result.ok("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.liklUserService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.ok("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		LiklUser liklUser = liklUserService.getById(id);
		if(liklUser==null) {
			return Result.error("未找到对应数据");
		}
		return Result.ok(liklUser);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param liklUser
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, LiklUser liklUser) {
        return super.exportXls(request, liklUser, LiklUser.class, "用户表");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, LiklUser.class);
    }

}
